﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dimas.Framework.Common.Base;
using Dimas.Framework.Common.Utils;
using Dimas.Framework.Entity;
using Dimas.Framework.Interface.Repostory;

namespace Dimas.Portal.DAL
{
    public class ADOSampleRepository : BaseRepository,IADOSampleRepository
    {
        public SampleInfo GetById(int Id)
        {
            SampleInfo result=null;
            var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Dimas_Sample"].ConnectionString;
            var spName="sp_Sample";
            var sqlParameter = new SqlParameter("@Id", Id);
            var ds = SqlHelper.ExecuteDataset(connectionString, spName, sqlParameter);
            if (ds != null)
            {
                if (ds.Tables.Count > 0)
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        var dr = ds.Tables[0].Rows[0];
                        result = Map(result, dr);
                    }
                }
            }
            return result;
        }

        private static SampleInfo Map(SampleInfo result, System.Data.DataRow dr)
        {
            result = new SampleInfo()
            {
                Id = (int)dr["Id"],
                Name = dr["Name"].ToString(),
                Length = (int)dr["Length"]
            };
            return result;
        }
    }
}
